/*
    This file is part of Epoch <http://code.google.com/p/epoch/>.
    
    Copyright (C) 2011  Adam Meily <meily.adam@gmail.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/


#include "Response.h"

Response::Response() : Message(), m_status(InvalidStatus)
{

}

Response::Response(const Response& other) : Message(other),
                                            m_status(other.m_status)
{

}

Response::Response(const QStringList& input) : Message(input)
{
    parseStatus();
}

Response::~Response()
{

}

Response& Response::operator=(const Response& other)
{
    m_status = other.m_status;
    Message::operator=(other);
    return *this;
}

bool Response::isNull() const
{
    return m_status == InvalidStatus;
}

Response::Status Response::status() const
{
    return m_status;
}

void Response::status(Response::Status status)
{
    m_status = status;
    setOperation();
}

void Response::setOperation()
{
    QString op;
    /*
    if(m_status == Handshake)
        op = "handshake";
    else if(m_status == PutCert)
        op = "put-cert";
    else if(m_status == PutDelta)
        op = "put-delta";
    else if(m_status == PutListing)
        op = "put-ls";
    else if(m_status == InvalidRequest)
        op = "invalid-request";
    */
    if(m_status == Ok)
        op = "ok";
    else if(m_status == InvalidRequest)
        op = "invalid-request";
    operation(op);
}

void Response::parseStatus()
{
    Status s = InvalidStatus;
    /*
    if(operation() == "handshake")
        s = Handshake;
    else if(operation() == "put-cert")
        s = PutCert;
    else if(operation() == "put-delta")
        s = PutDelta;
    else if(operation() == "put-ls")
        s = PutListing;
    else if(operation() == "invalid-request")
        s = InvalidRequest;
    */
    if(operation() == "ok")
        s = Ok;
    else if(operation() == "invalid-request")
        s = InvalidRequest;
    m_status = s;
}


